﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace copy
{
    public partial class choiseCopyExamples : Form
    {
        private choiseCopyExamples()
        {
            InitializeComponent();
        }

        public choiseCopyExamples(string dbpath)
        {
            InitializeComponent();
            db=new DBHelper(dbpath);
        }

        private DBHelper db = null;
        public int noticelistId = -1;
        public NoticeList noticeList_F = null;
        private void choiseCopyExamples_Load(object sender, EventArgs e)
        {
            Form f = this.Owner;

            if (f != null) this.Icon = f.Icon;
            List<NoticeList> ls = db.SelectnoticelistTable();
            if (ls != null)
            {
                if(ls.Count!=0)
                    cbNoticeList.Items.AddRange(ls.ToArray());
                else
                {
                    btnNext.Enabled = false;
                    cbNoticeList.Enabled = false;
                    this.DialogResult = DialogResult.None;
                }
                //cbNoticeList.Items.Add()
            }
            else
            {
                btnNext.Enabled = false;
                cbNoticeList.Enabled = false;
                this.DialogResult = DialogResult.None;
            }
            // SelectnoticelistTable
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (cbNoticeList.SelectedIndex != -1)
            {
                noticeList_F = (NoticeList) cbNoticeList.SelectedItem;
                this.noticelistId = noticeList_F.Id;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text) || string.IsNullOrEmpty(txtName.Text.Trim()))
            {
                MessageBox.Show("Please Type Name");
                txtName.Focus();
            }
            else
            {
                noticelistId = db.InsertnoticelistTable(txtName.Text);
                noticeList_F=new NoticeList();
                noticeList_F.Id = noticelistId;
                noticeList_F.Name = txtName.Text;
                this.DialogResult= DialogResult.OK;
                this.Close();
            }
        }

        private void choiseCopyExamples_FormClosing(object sender, FormClosingEventArgs e)
        {
            //if(noticelistId==-1)
            //    Application.Exit();
        }
    }
}
